<?php
/*************************************************

普汇云通API - the
Author: Wanghuabin <17-8-18>

*************************************************/
class Puhuiyuntong{
   // private static $PRIVATE_KEY = 'https://www.goodsure.cn/jiekou/8hjie/index.php?';
   // private static $PRIVATE_KEY = 'http://s6.goodsure.cn/jiekou/8hjie/index.php?';
    public  function login(){

        $url = "https://www.phyt88.com/v3/finance/head";
        //return $url;
        $params = array(
            'username'=>"phyt",
            'password'=>'A89ADC609E318320ECFAF802C9B376C5',
        );
        // return $url;
        $content = $this->juhecurl($url,$params,$ispost=1);
        return $content; 
    }

    public  function get_data($token,$datakey){

        $url = "https://www.phyt88.com/v3/finance/head?&token=".$token."&datakey=".$datakey;
       // return $url;die;
        $content = $this->juhecurl($url);
        return $content;
    }
    public  function get_object($token,$starttime,$endtime){
        $url = "https://www.phyt88.com/v3/finance/head?token=".$token."&page=1&size=9999&starttime=".$starttime."&endtime=".$endtime."&datakey=Subject";
       // return $url;

        $content = $this->juhecurl($url);
        return $content;
    }


    public  function get_type($token){
         //return $starttime;
        // $url = "http://113.108.110.189:84/jinrongjie8/jinrongjieservice?token=".$token."&datakey=".$datakey;
        $url = "https://www.phyt88.com/v3/finance/head?token=".$token."&datakey=typecount";
        //return $url;

        $content = $this->juhecurl($url);
        return $content;
    }


    public  function get_data_page($token,$page,$size,$starttime,$endtime,$datakey){
        $url = "https://www.phyt88.com/v3/finance/head?token=".$token."&page=".$page."&size=".$size."&starttime=".$starttime."&endtime=".$endtime."&datakey=".$datakey;
        $content = $this->juhecurl($url);
        return $content;
    }

     public  function bind_user($token,$phone,$relaname,$idcard,$userid){
        $url = "https://www.phyt88.com/v3/finance/head?token=".$token."&datakey=binduser";
        $params = array(
            'phone'=>$phone,
            'relaname'=>$relaname,
            'UserId'=>$userid,
        );
        $content = $this->juhecurl($url,$params,$ispost=1);
        return $content;
    }


    public function juhecurl($url,$params=false,$ispost=0){
        $httpInfo = array();
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
        curl_setopt( $ch, CURLOPT_USERAGENT , 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22' );
        curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 30 );
        curl_setopt( $ch, CURLOPT_TIMEOUT , 30);
        curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
        if( $ispost )
        {
            curl_setopt( $ch , CURLOPT_POST , true );
            curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );
            curl_setopt( $ch , CURLOPT_URL , $url );
        }
        else
        {
            if($params){
                curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
            }else{
                curl_setopt( $ch , CURLOPT_URL , $url);
            }
        }
        $response = curl_exec( $ch );
        if ($response === FALSE) {
            //echo "cURL Error: " . curl_error($ch);
            return false;
        }
        $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );
        $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
        curl_close( $ch );
        return $response;
    }


}